﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assessment.Management.SharedComponent.Params;
using Assessment.Management.SharedComponent.Constants;
using Assessment.Management.SharedComponent.Params.MenuManagers;
using Assessment.Management.SharedComponent.Params.ManagerParam;
using Assessment.Management.BIZ.CommonBIZ;
using Assessment.Management.SharedComponent.Params.CommonParam;

namespace Assessment.Management.BIZ
{
    public partial class MainController
    {
        private static MainController provider;
        private MainController() { }

        /// <summary>
        /// provider
        /// </summary>
        public static MainController Provider
        {
            get
            {
                if (provider == null)
                {
                    provider = new MainController();
                }
                return provider;
            }
        }
        //#region Execute
        public void Execute(BaseParam baseParam)
        {
            try
            {
                switch (baseParam.ControlInfo.BusinessType)
                {
                    case BusinessType.MenuManagers:
                        MenuManagersExecute(baseParam);
                        break;
                    case BusinessType.Account:
                        AccountsExecute(baseParam);
                        break;
                    case BusinessType.Subject:
                        ManagersExecute(baseParam);
                        break;
                    case BusinessType.Department:
                        ManagersExecute(baseParam);
                        break;
                    case BusinessType.IPAddres:
                        ManagersExecute(baseParam);
                        break;
                    case BusinessType.Poll:
                        ManagersExecute(baseParam);
                        break;
                    case BusinessType.Teacher:
                        ManagersExecute(baseParam);
                        break;
                    case BusinessType.Class:
                        ManagersExecute(baseParam);
                        break;
                    case BusinessType.TeacherClass:
                        ManagersExecute(baseParam);
                        break;
                    case BusinessType.ConfigData:
                        ConfigDataExecute(baseParam);
                        break;
                    default:
                        throw new NotSupportedException();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        private void ConfigDataExecute(BaseParam baseParam)
        {
            switch (baseParam.ControlInfo.FunctionType)
            {
                case FunctionType.GetListGroupQuestion:
                    {
                        GroupQuestionBIZ groupBiz = new GroupQuestionBIZ();
                        groupBiz.GetListGroupQuestion((GroupQuestionParam)baseParam);
                        break;
                    }
                case FunctionType.GetGroupQuestionByID:
                    {
                        GroupQuestionBIZ groupBiz = new GroupQuestionBIZ();
                        groupBiz.GetGroupQuestionByID((GroupQuestionParam)baseParam);
                        break;
                    }

                case FunctionType.GetListQuestionByType:
                    {
                        QuestionBIZ quesBiz = new QuestionBIZ();
                        quesBiz.GetListQuestionByType((QuestionParam)baseParam);
                        break;
                    }
                case FunctionType.GetListQuestion:
                    {
                        QuestionBIZ quesBiz = new QuestionBIZ();
                        quesBiz.GetListQuestion((QuestionParam)baseParam);
                        break;
                    }
                case FunctionType.GetListQuestionByGroupID:
                    {
                        QuestionBIZ quesBiz = new QuestionBIZ();
                        quesBiz.GetListQuestionByGroupID((QuestionParam)baseParam);
                        break;
                    }
                case FunctionType.GetListQuestionByID:
                    {
                        QuestionBIZ quesBiz = new QuestionBIZ();
                        quesBiz.GetListQuestionByID((QuestionParam)baseParam);
                        break;
                    }

                case FunctionType.GetListOptionByQuestionID:
                    {
                        OptionBIZ optBiz = new OptionBIZ();
                        optBiz.GetListOptionByQuestionID((OptionParam)baseParam);
                        break;
                    }
                case FunctionType.GetCountOptionByQuestionID:
                    {
                        OptionBIZ optBiz = new OptionBIZ();
                        optBiz.GetCountOptionByQuestionID((OptionParam)baseParam);
                        break;
                    }

                case FunctionType.GetListHitCountByQuestionIDSubjectIDClassID:
                    {
                        OptionBIZ optBiz = new OptionBIZ();
                        optBiz.GetListHitCountByQuestionIDSubjectIDClassID((OptionParam)baseParam);
                        break;
                    }

                case FunctionType.GetOptionHitByOptionID:
                    {
                        OptionHitBIZ optHitBiz = new OptionHitBIZ();
                        optHitBiz.GetOptionHitByOptionID((OptionHitParam)baseParam);
                        break;
                    }
                case FunctionType.GetListOptionHitByOptionID:
                    {
                        OptionHitBIZ optHitBiz = new OptionHitBIZ();
                        optHitBiz.GetListOptionHitByOptionID((OptionHitParam)baseParam);
                        break;
                    }
                case FunctionType.GetOptionHitBySubjectIDAndClassID:
                    {
                        OptionHitBIZ optHitBiz = new OptionHitBIZ();
                        optHitBiz.GetOptionHitBySubjectIDAndClassID((OptionHitParam)baseParam);
                        break;
                    }
                   case FunctionType.InsertNewOptionHit:
                    {
                        OptionHitBIZ optHitBiz = new OptionHitBIZ();
                        optHitBiz.InsertNewOptionHit((OptionHitParam)baseParam);
                        break;
                    }
                case FunctionType.UpdateOptionHitCount:
                    {
                        OptionHitBIZ optHitBiz = new OptionHitBIZ();
                        optHitBiz.UpdateOptionHitCount((OptionHitParam)baseParam);
                        break;
                    }
                case FunctionType.InsertAnswerOfQuestion:
                    {
                        QuestionStudentBIZ qsBiz = new QuestionStudentBIZ();
                        qsBiz.InsertAnswerOfQuestion((QuestionStudentParam)baseParam);
                        break;
                    }
                case FunctionType.GetListAnswerByQuestionIDSubjectIDClassID:
                    {
                        QuestionStudentBIZ qsBiz = new QuestionStudentBIZ();
                        qsBiz.GetListAnswerByQuestionIDSubjectIDClassID((QuestionStudentParam)baseParam);
                        break;
                    }
                default:
                    throw new NotSupportedException();
            }
        }

        private void ManagersExecute(BaseParam baseParam)
        {
            switch (baseParam.ControlInfo.FunctionType)
            {
                #region ManagerSubject
                case FunctionType.GetListSubjects:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.GetListSubjects((SubjectParam)baseParam);
                        break;
                    }
                case FunctionType.GetListSubjectByTeacherIDAndClassID:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.GetListSubjectByTeacherIDAndClassID((SubjectParam)baseParam);
                        break;
                    }
                case FunctionType.GetListSubjectByDepartmentID:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.GetListSubjectByDepartmentID((SubjectParam)baseParam);
                        break;
                    }
                case FunctionType.UpdateSubject:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.UpdateSubject((SubjectParam)baseParam);
                        break;
                    }
               
                case FunctionType.SearchSubjects:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.SearchSubjects((SubjectParam)baseParam);
                        break;
                    }

                case FunctionType.DeleteSubject:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.DeleteSubject((SubjectParam)baseParam);
                        break;
                    }
                case FunctionType.CreateSubject:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.CreateSubject((SubjectParam)baseParam);
                        break;
                    }
                case FunctionType.GetLastSubjectCode:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.GetLastSubjectCode((SubjectParam)baseParam);
                        break;
                    }
                case FunctionType.CheckExitsData:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.CheckExitsData((SubjectParam)baseParam);
                        break;
                    }
                case FunctionType.GetSubjectToEditByCode:
                    {
                        SubjectBIZ subjectBiz = new SubjectBIZ();
                        subjectBiz.GetSubjectToEditByCode((SubjectParam)baseParam);
                        break;
                    }

                #endregion

                #region ManagerDepartmen
                case FunctionType.GetListDepartment:
                    {
                        DepartmentBIZ deBiz = new DepartmentBIZ();
                        deBiz.GetListDepartment((DepartmentParam)baseParam);
                        break;
                    }
                #endregion

                #region ManagerPoll
                case FunctionType.GetListPoll:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.GetListPoll((PollParam)baseParam);
                        break;
                    }

                case FunctionType.GetPollInput:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.GetPollInput((PollParam)baseParam);
                        break;
                    }

                case FunctionType.CheckExitsDataConfig:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.CheckExitsDataConfig((PollParam)baseParam);
                        break;
                    }
                case FunctionType.CheckConfig:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.CheckConfig((PollParam)baseParam);
                        break;
                    }

                case FunctionType.GetListPollByDepartment:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.GetListPollByDepartment((PollParam)baseParam);
                        break;
                    }

                case FunctionType.GetLastPollCode:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.GetLastPollCode((PollParam)baseParam);
                        break;
                    }

                case FunctionType.GetPollByID:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.GetPollByID((PollParam)baseParam);
                        break;
                    }

                case FunctionType.SearchPollSetting:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.SearchPollSetting((PollParam)baseParam);
                        break;
                    }

                case FunctionType.CreatePoll:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.CreatePoll((PollParam)baseParam);
                        break;
                    }

                case FunctionType.UpdatePoll:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.UpdatePoll((PollParam)baseParam);
                        break;
                    }

                case FunctionType.DeletePoll:
                    {
                        PollBIZ pollBiz = new PollBIZ();
                        pollBiz.DeletePoll((PollParam)baseParam);
                        break;
                    }
                #endregion

                #region ManagerTeacher
                case FunctionType.GetListTeacherByDepartmentID:
                    {
                        TeacherBIZ teacherBiz = new TeacherBIZ();
                        teacherBiz.GetListTeacherByDepartmentID((TeacherParam)baseParam);
                        break;
                    }
                case FunctionType.GetTeachers:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.GetTeacher((TeacherParam)baseParam);
                        break;
                    }
             
                case FunctionType.UpdateTeacher:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.UpdateTeacher((TeacherParam)baseParam);
                        break;
                    }
                case FunctionType.CreateTeacher:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.CreateTeacher((TeacherParam)baseParam);
                        break;
                    }
                case FunctionType.DeleteTeacher:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.DeleteTeacher((TeacherParam)baseParam);
                        break;
                    }
                case FunctionType.CheckExitsTeacherData:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.CheckExitsTeacherData((TeacherParam)baseParam);
                        break;
                    }
                case FunctionType.GetLastTeacherCode:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.GetLastTeacherCode((TeacherParam)baseParam);
                        break;
                    }
                case FunctionType.SearchTeacher:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.SearchTeachers((TeacherParam)baseParam);
                        break;
                    }
                case FunctionType.GetTeacherToEditByCode:
                    {
                        TeacherBIZ teacherbiz = new TeacherBIZ();
                        teacherbiz.GetTeacherToEditByCode((TeacherParam)baseParam);
                        break;
                    }

                #endregion

                #region ManagerClass

                case FunctionType.GetListClassByTeacherID:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.GetListClassByTeacherID((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.GetListClassByDepartmentID:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.GetListClassByDepartmentID((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.GetClasss:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.GetClasses((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.SearchClasses:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.SearchClasses((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.DeleteClasses:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.DeleteClasses((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.UpdateClass:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.UpdateClass((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.CreateClass:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.CreateClass((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.CheckExitsClassData:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.CheckExitsData((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.GetClassToEditByCode:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.GetClassToEditByCode((ClassParam)baseParam);
                        break;
                    }
                case FunctionType.GetLastClassCode:
                    {
                        ClassBIZ classBIZ = new ClassBIZ();
                        classBIZ.GetLastClassCode((ClassParam)baseParam);
                        break;
                    }

                #endregion

                #region TeacherClass
                case FunctionType.CreateTeacherClass:
                    {
                        TeacherClassBIZ tcBIZ = new TeacherClassBIZ();
                        tcBIZ.CreateTeacherClass((TeacherClassParam)baseParam);
                        break;
                    }
                #endregion

                #region IP
                case FunctionType.CheckIP:
                    {
                        IPBIZ ipbiz = new IPBIZ();
                        ipbiz.CheckIP((IPParam)baseParam);
                        break;
                    }
                case FunctionType.CheckIDSubject:
                    {
                        IPBIZ ipbiz = new IPBIZ();
                        ipbiz.CheckIDSubject((IPParam)baseParam);
                        break;
                    }
                case FunctionType.CreateIP:
                    {
                        IPBIZ ipbiz = new IPBIZ();
                        ipbiz.CreateIP((IPParam)baseParam);
                        break;
                    }
                case FunctionType.DeleteIPByConfigID:
                    {
                        IPBIZ ipbiz = new IPBIZ();
                        ipbiz.DeleteIPByConfigID((IPParam)baseParam);
                        break;
                    }
                #endregion
                default:
                    throw new NotSupportedException();
            }
        }
        private void MenuManagersExecute(BaseParam baseParam)
        {
            switch (baseParam.ControlInfo.FunctionType)
            {
                case FunctionType.GetMenuManagers:
                    {
                        MenuManagersBIZ menuBiz = new MenuManagersBIZ();
                        menuBiz.GetMenuManagers((MenuManagersParam)baseParam);
                        break;
                    }
                case FunctionType.GetChildMenu:
                    {
                        MenuManagersBIZ menuBiz = new MenuManagersBIZ();
                        menuBiz.GetChildMenu((MenuManagersParam)baseParam);
                        break;
                    }

                default:
                    throw new NotSupportedException();
            }
        }

        private void AccountsExecute(BaseParam baseParam)
        {
            switch (baseParam.ControlInfo.FunctionType)
            {
                case FunctionType.GetAccount:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.GetAccount((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.GetPermission:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.GetPermission((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.CheckAccount:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.CheckAccount((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.GetAccountToEditByCode:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.GetAccountToEditByCode((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.CreateAccount:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.CreateAccount((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.UpdateAccount:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.UpdateAccount((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.DeleteAccount:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.DeleteAccounts((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.CheckExitsAccData:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.CheckExitsAccData((AccountParam)baseParam);
                        break;
                    }
                case FunctionType.GetLastAccountCode:
                    {
                        AccountBIZ accBiz = new AccountBIZ();
                        accBiz.GetLastAccountCode((AccountParam)baseParam);
                        break;
                    }
                default:
                    throw new NotSupportedException();
            }
        }
    }
}
